#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;
using ll = long long;
const int N = 1e6 + 10;
int r[N], d[N], s[N], t[N];
ll b[N];
int n, m;
bool check(int mid)
{
    for (int i = 1; i <= n; i++) b[i] = r[i] - r[i - 1];
    for (int i = 1; i <= mid; i++)
    {
        b[s[i]] -= d[i];
        b[t[i] + 1] += d[i];
    }
    for (int i = 1; i <= n; i++)
    {
        b[i] += b[i - 1];
        if (b[i] < 0) return true;
    }
    return false;
}
int main()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> r[i];
    for (int i = 1; i <= m; i++) cin >> d[i] >> s[i] >> t[i];
    if (!check(m))
    {
        cout << 0 << endl;
        return 0;
    }
    int l = 1, r = m;
    while (l < r)
    {
        int mid = l + r >> 1;
        if (check(mid)) r = mid;
        else l = mid + 1;
    }
    cout << -1 << endl;
    cout << l << endl;
    return 0;
}